package beast.phylodynamics.marsden;

import beast.evolution.tree.Tree;
import beast.evolution.tree.coalescent.TreeIntervals;
import beast.evolution.tree.coalescent.Coalescent;
import beast.phylodynamics.epidemiology.DeterministicCoalescentSIR;
import beast.util.TreeParser;
import beast.core.parameter.RealParameter;
import beast.phylodynamics.epidemiology.Volz2009TreeDistribution;

import java.io.IOException;
import java.io.PrintStream;

/**
 * Created by IntelliJ IDEA. User: Denise Kuehnert Date: Jun 4, 2013 Time:
 * 4:36:41 PM
 */
public class LikelihoodSurfaces {

    public static void main(String[] args) throws IOException, Exception {

        String[] param_name = {"beta", "gamma", "S0"};
        double[] paramTruth = {0.0075, 0.25, 999.0};
        double[] paramLowerBound = {0.0001, 0.10, 0};
        double[] paramUpperBound = {0.01, 0.50, 3000.0};
        int nsteps = 500;

        // Generate coodinate files:
        PrintStream coordBeta = new PrintStream("coordbeta.txt");
        PrintStream coordGamma = new PrintStream("coordgamma.txt");
        PrintStream coordS0 = new PrintStream("coordS0.txt");
        for (int i=0; i<nsteps; i++) {
            coordBeta.println(paramLowerBound[0]
                    + (paramUpperBound[0]-paramLowerBound[0])*i/(nsteps-1));
            coordGamma.println(paramLowerBound[1]
                    + (paramUpperBound[1]-paramLowerBound[1])*i/(nsteps-1));
            coordS0.println(paramLowerBound[2]
                    + (paramUpperBound[2]-paramLowerBound[2])*i/(nsteps-1));
        }
        coordBeta.close();
        coordGamma.close();
        coordS0.close();

        DeterministicCoalescentSIR volzSIR = new DeterministicCoalescentSIR();
        Volz2009TreeDistribution volzSIR2009 = new Volz2009TreeDistribution();

        double[] paramCurrent = new double[3];

        String[] trees = new String[1];
        int[] tips = new int[trees.length];

        //25 tips
//        trees[0] = "((20:1.7327013309920987,(2:1.5699517642369987,9:1.5699517642369987):0.1627495667551):0.3906420437073396,(((((12:1.4606660366895723,((22:0.7364772016601255,21:0.7364772016601255):0.6701138844558105,(15:1.3665082235172927,((3:1.020945860930602,(8:0.8653300121493379,10:0.8653300121493379):0.155615848781264):0.22753196406186138,(7:1.1290942502849537,19:1.1290942502849537):0.1193835747075096):0.11803039852482944):0.040082862598643354):0.054074950573636205):0.0074844678674776954,((17:0.012266430667138728,23:0.012266430667138728):1.3007893648454143,(24:0.9390090648133209,5:0.9390090648133209):0.3740467306992321):0.15509470904449696):0.038425441676050665,((18:0.5287382111016794,16:0.5287382111016794):0.6219873839148018,14:1.1507255950164812):0.35585035121661945):0.17026942978592519,11:1.6768453760190258):0.3913503628622723,((13:0.7724098713155667,(25:0.07463738743032255,4:0.07463738743032255):0.6977724838852442):0.9249671690996732,(6:1.2765864559055629,1:1.2765864559055629):0.4207905845096771):0.3708186984660582):0.05514763581814014);";
//        tips[0] = 25;

        //100 tips
        trees[0] = "(((21:0.590594559805572,((74:1.4589347959252121,((4:1.3046727543018992,((((18:0.9496491378172802,49:0.9692640255655149):1.293411897026722,(65:0.2510294877846082,(78:1.952924827956151,70:1.2615896413422085):0.0014905434996119737):1.6526334933282918):0.28021339647468047,((((26:0.7793384307588465,12:1.0129366946183822):0.25265856435627043,88:1.4579687870415494):0.6596655350159004,(11:0.09207570643294005,41:0.26417460268375415):2.2836796269699295):0.5414626037127679,((9:1.7354111753401256,99:0.6752781763150715):0.24458500320143806,58:1.066844302469427):0.16290446867755293):0.37360288444702583):0.6383971103116757,((((((((94:0.5389425680169229,72:1.3176429711879099):0.019760876329861787,67:0.9210062580769769):0.311021237836151,35:0.25652120164809844):0.1291782617976338,91:0.7882633268910517):1.056849813358106,79:2.217986133890834):0.26377692739991154,((((39:0.4477633763366118,2:0.7547695735284066):1.3987698710948848,69:0.6646281094028286):0.21628864975617823,33:1.895178985967446):0.16632477801636725,56:1.9215654162892832):0.7659415057305754):0.43818925146372045,(((96:0.06699733647498718,44:0.7920244844420701):1.8687357593713934,43:1.7166787125422136):0.1340514790811671,(7:0.30242123410145183,63:0.12838638757901322):1.1272162889490112):0.3455856209279986):0.46521345161249883,(17:4.123551644382504,54:2.1616365410121965):0.2063191606179373):0.8527825011254535):1.0163587935163445):0.042772644431579465,(83:0.5896406043090883,(28:0.7943857946078738,98:1.4223895820939392):0.45459652557770447):0.3014444245286567):1.6869468540175996):1.941602917931815,76:0.18603193794281703):0.030746681985597046):1.0245782976854043,(((86:2.250210465523703,(73:0.9613483003932783,95:0.37993656594412517):0.6315683512023034):0.050655178256629796,((90:0.8868991631240872,(81:1.2376581085580902,27:3.4305697780183912):2.480799745869467):1.022837634687411,23:0.724279884078296):2.2593217825785343):0.006903025954701825,(31:1.6909798498708826,(((55:1.0997575263844936,68:1.059843102818773):1.633925751003928,((34:0.692496274652914,(51:3.6890374505680246,(50:1.6199846134002467,(20:0.08171190421046326,(37:0.013580855339283104,10:1.8606888844358647):0.3191568127239819):0.6016134381610723):1.1817913238577447):0.6854790583857078):2.3880936839518867,25:0.964412115803114):0.5282473164898702):0.7682448267185649,(45:0.10693807154853108,29:0.4380405998042658):0.8215008229444152):0.8343451021382604):0.4019544642033601):0.9098032724111453):0.8255152796091134,(((((22:1.8009830737434012,(66:0.8751439143471664,61:0.7424004262014066):5.069579563873038):0.9273893867777661,((15:0.7042750304609111,((48:1.303416634148924,(64:0.6456344424898504,(((30:0.22044324866061693,92:1.4272365980298574):0.46893975372112173,46:1.5632800117047747):2.0688514176553436,89:2.2093728295202624):0.20569797257876665):0.3317069816588347):0.2520109152836447,59:1.0119877350538804):0.1663483994337831):1.32460760319238,(84:0.060988187236543645,(6:0.1449477211512562,(((77:1.415699410149566,36:1.1147825942779015):0.44514748539472393,(62:2.4387189676908427,80:2.242905159121932):1.5912650037971634):0.6229867640134721,97:1.8800399833564079):1.5262229606711175):0.29672311093040804):0.018189734501803834):0.8048336429146756):2.1018627545866404,(((100:0.25962935703532786,5:0.9381624382761942):0.6832167382136181,52:0.16258959184656163):1.283086264215644,((14:0.14130050886647894,(((((19:0.525123882007879,(47:0.5628924693191237,93:1.1200116355632304):0.23648568923520052):1.4682487435301859,57:1.2564377413212906):0.04160151183050864,87:0.04735741803953353):0.24013791470305001,((3:0.9409506263236072,53:1.5856757639332457):0.04667494465538802,13:0.9063230451757356):0.8341633399280433):1.3714228140866407,(32:0.27477782191556166,(85:1.5270391877925302,40:0.33406486345782405):0.7277291116354334):1.7568542224946757):0.6038938037740902):0.13519718077714415,(8:1.121561271441939,(60:1.0807184499690727,(1:1.5452558295270915,(((71:0.19446069728062731,38:0.6116106588009966):0.08096932694891557,(24:0.42324125836834803,75:0.1602039052079096):0.39837089704351847):0.9997377386227981,42:1.527770594818552):0.25583687957086454):1.9300489582473048):0.8459749245421619):0.0067750383559115335):0.7351726113403654):3.715598106742386):0.2406081965023481,16:0.3106824493593603):1.779853207812645,82:0.35597821126554763):0.07549249400125646):1.6177111314685155";
        tips[0] = 100;

        // all 245 tips
//        trees[2] = "(((((((((((233:0.6955967111603156,198:0.6955967111603156):0.14021726278152546,79:0.8358139739418411):0.2371408222226441,(172:0.35672813225298183,(30:0.11114029483538612,35:0.11114029483538612):0.2455878374175957):0.7162266639115034):0.096868837962653,(((38:0.3735191185528217,32:0.3735191185528217):0.39229959315571605,(224:0.3886510272331738,229:0.3886510272331738):0.377167684475364):0.08685215563597892,(101:0.24682061936594568,196:0.24682061936594568):0.605850247978571):0.3171527667826215):0.14657273838145435,240:1.3163963725085925):0.151402686975042,(148:0.8502621462463897,((187:0.2218914614395655,227:0.2218914614395655):0.1875283161639416,((203:0.0143421338853984,189:0.0143421338853984):0.25115917757000794,234:0.26550131145540634):0.14391846614810078):0.4408423686428826):0.6175369132372448):0.07507504401318077,(116:0.21804866081771657,186:0.21804866081771657):1.3248254426790989):0.10524927559301678,(108:0.5575308819625084,90:0.5575308819625084):1.0905924971273238):0.08457795190226658,(((((46:0.25823318903568193,99:0.25823318903568193):0.6298639004154232,115:0.8880970894511051):0.00352927147474813,(((((237:0.20741715038729058,36:0.20741715038729058):0.18443102512754628,212:0.39184817551483686):0.0032976040457390887,(124:0.23283126437516266,161:0.23283126437516266):0.1623145151854133):0.011369160272506118,9:0.40651493983308207):0.1494414444023171,220:0.5559563842353992):0.33566997669045406):0.3165344934937879,118:1.2081608544196412):0.3617909098173575,((((((162:0.034945690780505245,132:0.034945690780505245):0.19242962254313856,42:0.2273753133236438):0.17549828083562113,(((164:0.02493672768545574,60:0.02493672768545574):0.14923286629530885,(31:2.861517250267731E-4,207:2.861517250267731E-4):0.17388344225573782):0.19993388204264573,(71:0.22184743146580654,(157:0.050408750672636504,80:0.050408750672636504):0.17143868079317004):0.15225604455760378):0.028770118135854617):0.23343520726585498,154:0.6363088014251199):0.2880502604352615,(((111:0.03219949787489451,94:0.03219949787489451):0.17503222233260063,(199:0.017591236215728223,104:0.017591236215728223):0.18964048399176692):0.040289566553747935,141:0.24752128676124308):0.6768377750991383):0.355313383051572,84:1.2796724449119534):0.29027931932504525):0.1627495667551):0.1616741410359196,(214:1.5211513817045366,((86:0.6423759217102636,((236:0.3322929367219407,185:0.3322929367219407):0.1827825144107429,231:0.5150754511326836):0.12730047057757998):0.73511664196663,((180:0.3862334779611709,158:0.3862334779611709):0.5225168133863127,(54:0.0995536332436231,119:0.0995536332436231):0.8091966581038605):0.4687422723294099):0.1436588180276429):0.3732240903234818):0.22896790267142003,((((((((((48:0.4241004269162314,243:0.4241004269162314):0.09784151268971453,((74:0.04626858886278473,45:0.04626858886278473):0.3274362112137248,92:0.3737048000765095):0.1482371395294364):0.5175644010452773,225:1.0395063406512233):0.026114645996676566,(((83:0.1946664410900527,112:0.1946664410900527):0.2158928831153264,238:0.4105593242053791):0.41494843548179916,((95:0.6624421630615618,(98:0.3736316787398084,63:0.3736316787398084):0.2888104843217534):0.015930502252089696,47:0.6783726653136515):0.1471350943735268):0.24011322696072157):0.031243061705280573,73:1.0968640483531804):0.3638019883363919,((((160:0.11211745172100596,213:0.11211745172100596):0.16150366590205723,197:0.2736211176230632):0.4628560840370626,33:0.7364772016601258):0.6701138844558105,(((120:0.4487509591897667,204:0.4487509591897667):0.23514115314826545,((((117:0.23445717567867108,((137:0.056331038895975016,40:0.056331038895975016):0.12404803586902835,(139:0.10310711691621854,122:0.10310711691621854):0.07727195784878482):0.054078100913667715):0.027281350236161295,191:0.2617385259148324):0.2266784992072739,(((107:0.05571036530712714,93:0.05571036530712714):0.12217386013969955,205:0.1778842254468267):0.061749174821942976,72:0.23963340026876967):0.2487836248533366):0.024949902744727748,(64:0.3232306519751287,66:0.3232306519751287):0.19013627589170534):0.17052518447119813):0.6826161111792608,(((134:1.0617729361589328,(3:0.369845068592098,133:0.369845068592098):0.6919278675668348):0.06500744366185152,(((((232:0.021546584301352034,244:0.021546584301352034):0.344142745051379,59:0.365689329352731):0.08940911502227822,(51:0.06065352159978854,155:0.06065352159978854):0.3944449227752207):0.44485531898928143,(200:0.17317170680705862,169:0.17317170680705862):0.726782056557232):0.12099209756631146,((145:0.6541678249491143,(125:0.6113229366929425,18:0.6113229366929425):0.04284488825617183):0.307507747966552,(((173:0.18571664984559622,109:0.18571664984559622):0.17867471364482457,(7:0.0658969433606229,215:0.0658969433606229):0.2984944201297979):0.5009386486589174,85:0.8653300121493381):0.09634556076632816):0.059270288014935835):0.10583451889018214):0.12169744517167924,((((70:0.24626376861760324,68:0.24626376861760324):0.202113365316825,(194:0.2759212994177287,129:0.2759212994177287):0.17245583451669955):0.1082402998360783,57:0.5566174337705065):0.5724768165144474,((44:0.8676844249624589,(81:0.048359004317534815,223:0.048359004317534815):0.8193254206449241):0.03144437451077775,(((((135:0.02217996438076053,37:0.02217996438076053):0.20079958631531447,15:0.222979550696075):0.30733208388215183,210:0.5303116345782268):0.019679586316499353,241:0.5499912208947262):0.10025402948977513,52:0.6502452503845013):0.24888354908873533):0.22996545081171726):0.1193835747075096):0.11803039852482944):0.040082862598643354):0.05407495057363598):0.0074844678674776954,((((230:0.20357841368630236,50:0.20357841368630236):0.34349556416463,(178:0.012266430667138728,96:0.012266430667138728):0.5348075471837936):0.7625820889503805,((28:0.9434330370416533,(((61:0.07242909393280295,23:0.07242909393280295):0.23479701936494912,67:0.30722611329775207):0.11523249249406309,100:0.42245860579181516):0.5209744312498381):0.32781197583206234,5:1.2712450128737156):0.03841105392759725):0.0033997287112403907,(((235:0.02789630554792666,103:0.02789630554792666):0.10076698096962167,6:0.12866328651754833):0.8103457782957728,((21:0.05467586259720836,127:0.05467586259720836):0.7499656993517843,(174:0.7656118147305466,(142:0.5850056802792643,102:0.5850056802792643):0.18060613445128237):0.03902974721844599):0.13436750286432853):0.3740467306992321):0.15509470904449674):0.038425441676050665,((136:0.9677314899312848,(((146:0.011349922960334435,239:0.011349922960334435):0.2842512119673697,(201:0.11182495242383439,177:0.11182495242383439):0.18377618250386973):0.3129454953546442,(143:0.0035453008061563374,216:0.0035453008061563374):0.605001329476192):0.3591848596489364):0.2348247769399423,(((((149:0.22758379023380604,166:0.22758379023380604):0.441688397673925,((41:0.3322776423307512,17:0.3322776423307512):0.14240197672737986,((152:0.18721514171821152,159:0.18721514171821152):0.06417088823374106,((226:0.15128689471622314,179:0.15128689471622314):0.0067865726840588,167:0.15807346740028194):0.09331256255167064):0.22329358910617847):0.19459256884959997):0.0010930897008205598,(((((130:0.13697614690031212,19:0.13697614690031212):0.1556390440223976,(221:0.10231532304161384,113:0.10231532304161384):0.19029986788109587):0.18149349857988994,(110:0.18834896760392006,20:0.18834896760392006):0.2857597218986796):0.003475660991485885,(14:0.07492552776593131,217:0.07492552776593131):0.40265882272815423):0.05115386060759408,(53:0.35364413984485843,140:0.35364413984485843):0.1750940712568212):0.14162706650687196):0.38161461281194176,245:1.0519798904204933):0.09874570459598808,((156:0.9507599951088002,((121:0.004259389439384087,123:0.004259389439384087):0.06344738090632385,39:0.06770677034570793):0.8830532247630922):0.19462081399941344,(((((114:0.47470230915442047,34:0.47470230915442047):0.16424582016417677,((65:0.22392905261685803,105:0.22392905261685803):0.3909817191951903,(((29:0.0791638720399086,69:0.0791638720399086):0.039560932068283705,181:0.1187248041081923):0.28923515555720103,208:0.40795995966539333):0.206950812146655):0.024037357506548895):0.23532349664389995,((106:0.0015754429076402232,43:0.0015754429076402232):0.24118348050045535,126:0.24275892340809557):0.6315127025544016):0.08721296138400114,(((2:0.0304985617330793,4:0.0304985617330793):0.00863604774277027,168:0.03913460947584957):0.8163217477494533,(175:0.20482219199414375,76:0.20482219199414375):0.6506341652311591):0.10602823012119544):0.10346825662582781,((55:0.3951313616811536,8:0.3951313616811536):0.665434039630213,((((58:0.6203790340924247,(88:0.3838148173248017,218:0.3838148173248017):0.23656421676762296):0.0307294654231558,171:0.6511084995155805):0.04984065823744177,195:0.7009491577530222):0.24342106777978745,((151:0.21100802668854302,49:0.21100802668854302):0.600667885920686,16:0.811675912609229):0.1326943129235807):0.11619517577855687):0.004387442660959584):0.08042796513588746):0.005344785908267813):0.05183067185474566):0.3040196793618736):0.17026942978592519,((((27:0.008745783438392607,176:0.008745783438392607):0.0346849214713818,82:0.04343070490977441):0.2166861390994037,193:0.2601168440091781):1.166625135381603,((12:0.2814908996940111,97:0.2814908996940111):0.8716791748539319,(25:0.41496509775598067,((188:0.018499592191076886,138:0.018499592191076886):0.25668984144183504,89:0.27518943363291193):0.13977566412306874):0.7382049767919623):0.2735719048428382):0.25010339662824466):0.3913503628622723,(((((182:0.2836112687761534,242:0.2836112687761534):0.08505667133173889,11:0.3686679401078923):0.21699666682762087,131:0.5856646069355131):0.1867452643800538,(((153:0.10983208776720721,228:0.10983208776720721):0.20167938981497846,211:0.31151147758218567):0.146907349821229,((24:0.07463738743032255,190:0.07463738743032255):0.3750026945181548,147:0.4496400819484774):0.008778745454937287):0.31399104391215227):0.924967169099673,((183:0.1626887650299671,87:0.1626887650299671):1.3028585412048237,((((192:1.0086093884575675,(184:0.9581405521641553,163:0.9581405521641553):0.050468836293412256):0.2812539220150916,(((((75:0.5980640452438888,165:0.5980640452438888):0.4282395110734112,78:1.0263035563173):0.10997888368027486,((((144:0.07076058964647514,13:0.07076058964647514):0.21414114144085605,128:0.2849017310873312):0.38482005694835086,26:0.669721788035682):0.35842786677739524,170:1.0281496548130773):0.10813278518449754):0.01609087084087868,(22:0.025400280250206908,1:0.025400280250206908):1.1269730305882466):0.12421314506710956,(((91:0.49465986133119433,206:0.49465986133119433):0.28429416551135644,62:0.7789540268425508):0.34337813526864536,(209:0.7202780440806722,(219:0.06423486056776584,56:0.06423486056776584):0.6560431835129064):0.40205411803052393):0.15425429379436695):0.013276854567096041):0.1291352770611054,((10:0.114182440439905,222:0.114182440439905):0.8648036753645074,150:0.9789861158044124):0.4400124717293521):0.03990426993392382,(202:0.920512328860912,77:0.920512328860912):0.5383905286067763):0.006644448767102462):0.23182973418044917):0.3708186984660582):0.05514763581814014);";
//        tips[2] = 245;

        Tree tree;

        double logLvolzSIR2009;

        for (int treeIdx = 0; treeIdx < trees.length; treeIdx++) {
            for (int paramIdx = 0; paramIdx < 3; paramIdx++) {

                tree = new TreeParser(trees[treeIdx], false);

                TreeIntervals treeIntervals = new TreeIntervals();
                treeIntervals.init(tree);

                paramCurrent[paramIdx] = paramTruth[paramIdx];
                int param1Idx = (paramIdx+1)%3;
                int param2Idx = (paramIdx+2)%3;
                double param1Step = (paramUpperBound[param1Idx] - paramLowerBound[param1Idx]) / (nsteps-1);
                double param2Step = (paramUpperBound[param2Idx] - paramLowerBound[param2Idx]) / (nsteps-1);
                
                PrintStream [] outFiles = new PrintStream[4];
                outFiles[0] = new PrintStream(
                        String.format("fix_%s_gammatree.txt",
                        param_name[paramIdx],treeIdx,coordBeta));
//              outFiles[1] = new PrintStream(
//                      String.format("fix_%s_%d_VolzSIR2009.txt",
//                      param_name[paramIdx],treeIdx));
//              outFiles[2] = new PrintStream(
//                      String.format("fix_%s_%d_BDSIR.txt",
//                      param_name[paramIdx],treeIdx));

                for (int i = 0; i < nsteps; i++) {
                    for (int j = 0; j < nsteps; j++) {

                        paramCurrent[param1Idx] = paramLowerBound[param1Idx] + i * param1Step;
                        paramCurrent[param2Idx] = paramLowerBound[param2Idx] + j * param2Step;
                        
                        
                        ///// Volz 2012

                        volzSIR.setInputValue("beta", new RealParameter(String.valueOf(paramCurrent[0])));
                        volzSIR.setInputValue("gamma", new RealParameter(String.valueOf(paramCurrent[1])));
                        volzSIR.setInputValue("n_S0", new RealParameter(String.valueOf(paramCurrent[2])));
                        volzSIR.setInputValue("origin", new RealParameter("13.3814350414"));
                        volzSIR.setInputValue("integrationStepCount", 1000);

                        volzSIR.initAndValidate();

                        // Restructured since Denise wrote this -Alex
                        //Volz2012PopulationFunction volz2012 = new Volz2012PopulationFunction();

                        Coalescent coal = new Coalescent();
                        coal.initByName("treeIntervals", treeIntervals,
                                "populationModel", volzSIR);

                        double logVolzSIR = coal.calculateLogP();
                        outFiles[0].print((Double.isInfinite(logVolzSIR) ? "NA" : logVolzSIR) + " ");

                        
                        ///// Volz 2009
                        //// "Restructured since Denise wrote this" -Alex

                        //volzSIR2009.setInputValue("treeIntervals", new TreeIntervals(tree));
                        //volzSIR2009.setInputValue("beta", new RealParameter(String.valueOf(paramCurrent[0])));
                        //volzSIR2009.setInputValue("delta", new RealParameter(String.valueOf(paramCurrent[1])));
                        //volzSIR2009.setInputValue("S0", new RealParameter(String.valueOf(paramCurrent[2])));
                        //volzSIR2009.setInputValue("T", new RealParameter("13.020168"));

                        //try {
                        //    volzSIR2009.initAndValidate();
                        //    logLvolzSIR2009 = volzSIR2009.calculateLogP();

                        //} catch (Exception e) {
                        //    logLvolzSIR2009 = Double.NaN;
                        //}
                        //outFiles[1].print((Double.isInfinite(logLvolzSIR2009) ? "NA" : logLvolzSIR2009) + "\t");


                        ///// BDSIR
                        
//                        HybridSEIREpidemic sir = new HybridSEIREpidemic();
//                        sir.initByName(
//                                "tree", tree,
//                                "birth", new RealParameter(String.valueOf(paramCurrent[0])),
//                                "death", new RealParameter(String.valueOf(paramCurrent[1])),
//                                "sampling", "0",
//                                "origin", new RealParameter("2.5"),
//                                "S0", new RealParameter(String.valueOf(paramCurrent[2])),
//                                "Nt", "10001",
//                                "Nsamples", "101",
//                                "simulationType", "SAL", "isDeterministic", "true");
//
//                        sir.initTraj(paramCurrent[0], 0., new Double[]{paramCurrent[1]}, new Double[]{0.}, 2.5, tree.getLeafNodeCount(), 100, 1000, sir.times);
//
//                        BDSIR bdsir = new BDSIR();
//                        bdsir.setInputValue("tree", tree);
//                        bdsir.setInputValue("birthRate", new RealParameter(new Double[]{paramCurrent[0] * paramCurrent[2]}));
//                        bdsir.setInputValue("deathRate", new RealParameter(String.valueOf(paramCurrent[1])));
//                        bdsir.setInputValue("samplingRate", new RealParameter("0"));
//                        bdsir.setInputValue("rho", new RealParameter(new Double[]{tips[treeIdx] / 245.}));
//                        bdsir.setInputValue("S0", new RealParameter(String.valueOf(paramCurrent[2])));
//                        bdsir.setInputValue("origin", new RealParameter("2.5"));
//                        bdsir.setInputValue("dS", new RealParameter(sir.get_dS()));
//                        bdsir.setInputValue("dR", new RealParameter(sir.get_dR()));
//                        bdsir.setInputValue("checkTreeConsistent", false);
//
//                        bdsir.initAndValidate();
//
//                        double logLbdsir;
//                        try {
//                            logLbdsir = bdsir.calculateTreeLogLikelihood(tree);
//
//                        } catch (Exception e) {
//                            logLbdsir = Double.NaN;
//                        }
//
//                        outFiles[2].println((Double.isInfinite(logLbdsir) ? "NA" : logLbdsir) + "\t");

                    }

                    outFiles[0].println();
//                  outFiles[1].println();
//                  outFiles[2].println();
                }
            }
        }
    }
}
